﻿using Microsoft.Win32;
using System;
using System.IO;

namespace JYYQ.BMS
{
    public static class FileDialogHelper
    {
        public static string GetOpenFilePath()
        {
            string path = Directory.GetCurrentDirectory() + "\\Data";

            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title = "选择存储数据的路径...";
            ofd.InitialDirectory = path;
            ofd.Filter = "Excel文件|*.xls";

            if (ofd.ShowDialog() != true)
            {
                return path;
            }

            return ofd.FileName;
        }

        public static string GetSaveFilePath()
        {
            string path = Directory.GetCurrentDirectory() + "\\Data";
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            string filename = string.Format("数据{0}.xls", DateTime.Now.ToString("yyyy-MM-d-HH-m-ss"));
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Title = "选择存储数据的路径...";
            sfd.InitialDirectory = path;
            sfd.FileName = filename;
            sfd.Filter = "Excel文件|*.xls";

            if (sfd.ShowDialog() != true)
            {
                return path + filename;
            }
            return sfd.FileName;
        }
    }
}